*********************************************************************
*** Replication Code for Main Results, Appendix C, and Appendix G ***
*** Title: Relative Gains in the Shadow of a Trade War 			  ***
*** Authors: Eddy S. F. Yeung and Kai Quek           			  ***
*** Version: December 6, 2021                        			  ***
*********************************************************************

/// Stata version: 17.0 ///
clear all
/* ssc install estout // if not yet installed */
cd "~/Downloads/trade_replication" // change to your own working directory

/* Import the main dataset that contains all survey responses */
insheet using "trade.csv"

/*** Results Reported in the Main Text ***/
** Table 1: Average Treatment Effects among Groups Presented with the Removal of Import Limits
ttest supp1 if exp_group == 3 | exp_group == 6, by(exp_group)
ttest supp1 if exp_group == 4 | exp_group == 8, by(exp_group)

** Table 2: Average Treatment Effects among Groups Presented with the Imposition of Import Limits
ttest supp1 if exp_group == 1 | exp_group == 5, by(exp_group)
ttest supp1 if exp_group == 2 | exp_group == 7, by(exp_group)

** Footnote 73: Average Treatment Effects in Terms of Percentage Support
prtest supp2 if exp_group == 3 | exp_group == 6, by(exp_group)
prtest supp2 if exp_group == 4 | exp_group == 8, by(exp_group)
prtest supp2 if exp_group == 1 | exp_group == 5, by(exp_group)
prtest supp2 if exp_group == 2 | exp_group == 7, by(exp_group)

** Footnote 88: Average Treatment Effects of Pure Relative Gains on Non-Republicans
ttest supp1 if (exp_group == 3 | exp_group == 6) & republic == 0, by(exp_group)

/*** Results Reported in the Appendix ***/
** Appendix G: Average Treatment Effects After Reweighting Sample
// Generate the dummy variables required for the analysis
gen age1834 = .
replace age1834 = 1 if age >= 18 & age <= 34
replace age1834 = 0 if age >= 34 & age <= 999

gen vignette = .
replace vignette = 1 if exp_group == 5 | exp_group == 6 | exp_group == 7 | exp_group == 8
replace vignette = 0 if exp_group == 1 | exp_group == 2 | exp_group == 3 | exp_group == 4

// Compute the ATEs after the sample reweighting (Table A10)
ebalance age1834 female college democrat, manualtargets(.2978 .5156 .3225 .5) 
	// Note 1: see "ebalance.ado" for the source code
	// Note 2: the weights are set according to those reported in Table A9 
svyset [pweight = _webal]
svy: reg supp1 vignette if (exp_group == 3 | exp_group == 6)
svy: reg supp1 vignette if (exp_group == 4 | exp_group == 8)
svy: reg supp1 vignette if (exp_group == 1 | exp_group == 5)
svy: reg supp1 vignette if (exp_group == 2 | exp_group == 7)

** Appendix C: ordered probit regressions controlling for demographic and attitudinal variables
// Group 3 vs. Group 6 (Table A1)
eststo A1: oprob supp1 vignette female white black hisp asian ///
	if exp_group == 3 | exp_group == 6
eststo A2: oprob supp1 vignette income college democrat republic ///
	if exp_group == 3 | exp_group == 6
eststo A3: oprob supp1 vignette female white black hisp asian ///
	age income college democrat republic ///
	if exp_group == 3 | exp_group == 6
eststo A4: oprob supp1 vignette female white black hisp asian ///
	age income college democrat republic married pol_know ///
	if exp_group == 3 | exp_group == 6
eststo A5: oprob supp1 vignette female white black hisp asian ///
	age income college democrat republic married pol_know ///
	unemployed union global patriot chauvin ///
	if exp_group == 3 | exp_group == 6
eststo A6: oprob supp1 vignette female white black hisp asian ///
	age income college democrat republic married pol_know ///
	unemployed union global patriot chauvin ///
	family econ_sit immi_econ immi_cult ///
	if exp_group == 3 | exp_group == 6
esttab A* using "Table A1.rtf", replace se pr2 star(* 0.10 ** 0.05 *** 0.01) compress
eststo clear

// Group 4 vs. Group 8 (Table A2)
eststo A1: oprob supp1 vignette female white black hisp asian ///
	if exp_group == 4 | exp_group == 8
eststo A2: oprob supp1 vignette income college democrat republic ///
	if exp_group == 4 | exp_group == 8
eststo A3: oprob supp1 vignette female white black hisp asian ///
	age income college democrat republic ///
	if exp_group == 4 | exp_group == 8
eststo A4: oprob supp1 vignette female white black hisp asian ///
	age income college democrat republic married pol_know ///
	if exp_group == 4 | exp_group == 8
eststo A5: oprob supp1 vignette female white black hisp asian ///
	age income college democrat republic married pol_know ///
	unemployed union global patriot chauvin ///
	if exp_group == 4 | exp_group == 8
eststo A6: oprob supp1 vignette female white black hisp asian ///
	age income college democrat republic married pol_know ///
	unemployed union global patriot chauvin ///
	family econ_sit immi_econ immi_cult ///
	if exp_group == 4 | exp_group == 8
esttab A* using "Table A2.rtf", replace se pr2 star(* 0.10 ** 0.05 *** 0.01) compress
eststo clear

// Group 1 vs. Group 5 (Table A3)
eststo A1: oprob supp1 vignette female white black hisp asian ///
	if exp_group == 1 | exp_group == 5
eststo A2: oprob supp1 vignette income college democrat republic ///
	if exp_group == 1 | exp_group == 5
eststo A3: oprob supp1 vignette female white black hisp asian ///
	age income college democrat republic ///
	if exp_group == 1 | exp_group == 5
eststo A4: oprob supp1 vignette female white black hisp asian ///
	age income college democrat republic married pol_know ///
	if exp_group == 1 | exp_group == 5
eststo A5: oprob supp1 vignette female white black hisp asian ///
	age income college democrat republic married pol_know ///
	unemployed union global patriot chauvin ///
	if exp_group == 1 | exp_group == 5
eststo A6: oprob supp1 vignette female white black hisp asian ///
	age income college democrat republic married pol_know ///
	unemployed union global patriot chauvin ///
	family econ_sit immi_econ immi_cult ///
	if exp_group == 1 | exp_group == 5
esttab A* using "Table A3.rtf", replace se pr2 star(* 0.10 ** 0.05 *** 0.01) compress
eststo clear

// Group 2 vs. Group 7 (Table A4)
eststo A1: oprob supp1 vignette female white black hisp asian ///
	if exp_group == 2 | exp_group == 7
eststo A2: oprob supp1 vignette income college democrat republic ///
	if exp_group == 2 | exp_group == 7
eststo A3: oprob supp1 vignette female white black hisp asian ///
	age income college democrat republic ///
	if exp_group == 2 | exp_group == 7
eststo A4: oprob supp1 vignette female white black hisp asian ///
	age income college democrat republic married pol_know ///
	if exp_group == 2 | exp_group == 7
eststo A5: oprob supp1 vignette female white black hisp asian ///
	age income college democrat republic married pol_know ///
	unemployed union global patriot chauvin ///
	if exp_group == 2 | exp_group == 7
eststo A6: oprob supp1 vignette female white black hisp asian ///
	age income college democrat republic married pol_know ///
	unemployed union global patriot chauvin ///
	family econ_sit immi_econ immi_cult ///
	if exp_group == 2 | exp_group == 7
esttab A* using "Table A4.rtf", replace se pr2 star(* 0.10 ** 0.05 *** 0.01) compress
eststo clear
